package com.tool.engine.export.task;


import com.tool.engine.export.function.ProcessFunction;
import lombok.Data;

import java.util.List;

@Data
public abstract class AbstractExportTask<T> implements Task<T> {

    private ProcessFunction<T> consumer;

    private Boolean all;

    private Boolean dynamic;

    private String fileName;

    private String sheetName;

    private Class<T> clazz;

    protected AbstractExportTask(ProcessFunction<T> consumer, Boolean all, Boolean dynamic, String fileName, String sheetName,  Class<T> clazz) {
        this.consumer = consumer;
        this.all = all;
        this.dynamic = dynamic;
        this.fileName = fileName;
        this.sheetName = sheetName;
        this.clazz = clazz;
    }
    @Override
    public final List<T> process(int batch, long offset) {
        before(batch, offset);
        List<T> result = consumer.apply(batch, offset);
        after(batch, offset);
        return result;
    }
    @Override
    public final Class<?> getTaskType(){
        return clazz;
    }

    @Override
    public final Boolean isAll() {
        return all;
    }

    @Override
    public final Boolean isDynamic() {
        return dynamic;
    }


    @Override
    public void before(int batch, long offset) {

    }

    @Override
    public void after(int batch, long offset) {

    }

}
